package com.uflower.product.web;

import com.uflower.product.entity.CategoryEntity;
import com.uflower.product.service.CategoryService;

import com.uflower.product.vo.Catelog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/product")
public class IndexController {
    @Autowired
    private CategoryService categoryService;
    @GetMapping({"/","/index"})
    public String indexPage(Model model){
        List<CategoryEntity> categorys = categoryService.getLevel1Categorys();
        model.addAttribute("categorys",categorys);
        return "index";
    }
    @ResponseBody
    @GetMapping("/index/catelog.json")
    public Map<String,List<Catelog2Vo>> getCatelogJson(){
        Map<String,List<Catelog2Vo>> catelogJson = categoryService.getCatelogJson();
        return catelogJson;
    }
}
